<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2018/11/26
 * Time: 下午6:05
 */

namespace Api\Service;


class ShareService extends BaseService
{
    public $shareTypeModel;
    public $shareModel;
    public function __construct()
    {
        $this->shareTypeModel=M('sharetype');
        $this->shareModel=M('share');
    }


    /**
     * 查询分享类型
     * @param $where
     * @param $filed
     * @return mixed
     */
    public function queryType($where,$filed=null){
       return $this->shareTypeModel->field($filed)->where($where)->select();
    }


    /**
     * 查询分享列表
     * @param $where
     * @param $page
     * @param $page_num
     * @return mixed
     */
    public function queryShare($where,$page=1,$page_num=20){
       $re=$this->shareModel
           ->field('waoo_share.*,waoo_sharetype.type_name,waoo_collections.id as collections_id')
           ->join('waoo_sharetype on waoo_sharetype.type_id=waoo_share.share_type')
           ->join('LEFT JOIN waoo_collections on waoo_share.id=waoo_collections.share_id')
           ->where($where)
           ->order('waoo_share.ord asc,waoo_share.id desc')
           ->page($page,$page_num)
           ->select();
       return $re;
       //echo $this->shareModel->getLastSql();die;
    }

    /**
     * 查询类型
     * @param $where
     * @return mixed
     */
    public function countShare($where){
        $re=$this->shareModel
            ->join('waoo_sharetype on waoo_sharetype.type_id=waoo_share.share_type')
            ->where($where)
            ->count();
        return $re;
    }

}